package com.zhw.mapper;

import com.github.pagehelper.Page;
import com.zhw.pojo.dto.CustomerLossQueryDTO;
import com.zhw.pojo.entry.Customer;
import com.zhw.pojo.dto.CustomerQueryDTO;
import com.zhw.pojo.entry.CustomerLoss;
import com.zhw.pojo.entry.CustomerReprieve;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface CustomerMapper {


    Page<Customer> page(CustomerQueryDTO customerQueryDTO);



    @Select("select area from customer\n" +
            "GROUP BY area")
    List<String> getAddress();


    void save(Customer customer);

    @Select("select * from customer where id=#{id}")
    Customer getByID(Integer id);


    void update(Customer c);

    @Delete("delete from customer where id=#{id}")
    void delete(Integer id);

    @Select("select * from customer")
    List<Customer> getName();

    Page<CustomerLoss> getLossPage(CustomerLossQueryDTO customerLossQueryDTO);

    List<Customer> getLossCustomer(List<Integer> ids);



    @Select("select order_date from customer_order\n" +
            "where cus_id=#{id}\n" +
            "order by order_date desc\n" +
            "LIMIT 1")
    String getLastOrderTimeById(Integer id);

    void insertLose(List<CustomerLoss> losses);

    List<Integer> getLossId();

    @Select("select c.id from customer_loss cl left join customer c on cl.cus_no=c.khno")
    List<Integer> getLossalreadyExistsId();

    @Select("select * from customer_loss where id=#{id}")
    CustomerLoss getLossByID(Integer id);

    @Select("select * from customer_reprieve where loss_id=#{id}")
    List<CustomerReprieve> getReprieveByLossID(Integer id);

    void addReprieve(CustomerReprieve customerReprieve);


    void updateLoss(CustomerLoss customerLoss);

    @Select("select * from customer_reprieve where id=#{id}")
    CustomerReprieve getReprieveByID(Integer id);


    void updateReprieve(CustomerReprieve customerReprieve);

    @Delete("delete from customer_reprieve where id=#{id`}")
    void deleteReprieveByID(Integer id);

    @Select("select name from customer where id =#{id}")
    String getNameByID(Integer id);
}
